//
//  ToturialPageView.m
//  Unity-iPhone
//
//  Created by Karl on 2017/3/28.
//
//

#import "ToturialPageView.h"

@implementation ToturialPageView{
    
    NSDictionary *_titleDic;
    NSDictionary *_leftDic;
    NSDictionary *_rightDic;
    
    UIImageView *_title;
    UIImageView *_left;
    UIImageView *_right;
}

- (instancetype)initWithDictionary:(NSDictionary *)dic{
    self = [super init];
    if (self) {
        
        _titleDic = [dic objectForKey:@"title"];
        _leftDic = [dic objectForKey:@"left"];
        _rightDic = [dic objectForKey:@"right"];
        
        _title = [UIImageView new];
        [_title setImage:kImgFromFile([_titleDic objectForKey:@"image"], @"png")];
        [self addSubview:_title];
        
        _left = [UIImageView new];
        [_left setImage:kImgFromFile([_leftDic objectForKey:@"image"], @"png")];
        [self addSubview:_left];
        
        _right = [UIImageView new];
        [_right setImage:kImgFromFile([_rightDic objectForKey:@"image"], @"png")];
        [self addSubview:_right];
        
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    CGFloat scale = 1.0;
    if (isPad) {
        scale = SizeScaleX;
    }else{
        scale = SizeScaleY;
    }
    _title.top = [[_titleDic objectForKey:@"top"] floatValue] * scale;
    _title.width = [[_titleDic objectForKey:@"width"] floatValue] * scale;
    _title.height = [[_titleDic objectForKey:@"height"] floatValue] * scale;
    _title.centerX = self.width/2;
        
    _left.bottom = self.bottom - [[_leftDic objectForKey:@"bottom"] floatValue] * scale;
    _left.left = [[_leftDic objectForKey:@"left"] floatValue] * scale;
    _left.width = [[_leftDic objectForKey:@"width"] floatValue] * scale;
    _left.height = [[_leftDic objectForKey:@"height"] floatValue] * scale;
        
    _right.bottom = self.bottom - [[_rightDic objectForKey:@"bottom"] floatValue] * scale;
    _right.right = self.width - [[_rightDic objectForKey:@"right"] floatValue] * scale;
    _right.width = [[_rightDic objectForKey:@"width"] floatValue] * scale;
    _right.height = [[_rightDic objectForKey:@"height"] floatValue] * scale;
}

@end
